package co.bugu.code.analysis.application.converter;

import org.gitlab4j.api.models.Branch;
import org.springframework.beans.BeanUtils;

/**
 * @author daocers
 * @date 2025/6/3 15:23
 */
public class BranchConverter {


//    实现从gitlab4j的Branch对象转换为infra的Branch对象
    public static co.bugu.code.analysis.infra.entity.Branch convert(Long projectId, Branch branch) {
        co.bugu.code.analysis.infra.entity.Branch infraBranch = new co.bugu.code.analysis.infra.entity.Branch();
        BeanUtils.copyProperties(branch, infraBranch);
        infraBranch.setProjectId(projectId);
        infraBranch.setProjectName();
        infraBranch.setName(branch.getName());
        infraBranch.setLatestCommitMessage(branch.getCommit().getMessage());
        infraBranch.setLatestCommitAuthor(branch.getCommit().getAuthorName());
        infraBranch.setLatestCommitTime(branch.getCommit().getCommittedDate());
        infraBranch.setLatestCommitId(branch.getCommit().getId());
        infraBranch.setIsProtected(branch.getProtected() ? 1 : 0);
        infraBranch.setIsDefault(branch.getDefault() ? 1 : 0);
        infraBranch.setMerged(branch.getMerged() ? 1 : 0);
        infraBranch.setDevelopersCanMerge(branch.getDevelopersCanMerge() ? 1 : 0);
        infraBranch.setDevelopersCanPush(branch.getDevelopersCanPush() ? 1 : 0);
        infraBranch.setCanPush(branch.getCanPush() ? 1 : 0);
        return infraBranch;
    }
}
